﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityPlayerBuffExt.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-15
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityPlayerBuffExt
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFCityPlayerBuffExt.h"



NFCityPlayerBuffExt::NFCityPlayerBuffExt()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFCityPlayerBuffExt::~NFCityPlayerBuffExt()
{
}

int NFCityPlayerBuffExt::CreateInit()
{
    return 0;
}

int NFCityPlayerBuffExt::ResumeInit()
{
    return 0;
}

int NFCityPlayerBuffExt::Init(const proto_ff::RoleBuffDataCS* pBuffData)
{
    CHECK_NULL(0, pBuffData);
    m_stData.FromPb(*pBuffData);
    return 0;
}

int NFCityPlayerBuffExt::MakeBuffData(proto_ff::BattlePlayerHero* pPlayerHero)
{
    auto pBuffList = pPlayerHero->mutable_buff_list();
    for (auto iter = m_stData.buff.list_begin(); iter != m_stData.buff.list_end(); ++iter)
    {
        auto pBuff = &(iter->second);
        auto pBufferInfo = pBuffList->add_buff_list();
        pBufferInfo->set_buff_desc_id(pBuff->id);
        pBufferInfo->set_buff_id(0);
        pBufferInfo->set_caster_id(0);
        pBufferInfo->set_left_time(pBuff->left_time);
        pBufferInfo->set_stack(pBuff->layer);
    }
    return 0;
}

int NFCityPlayerBuffExt::AddBuff(const proto_ff::CityBuffOneCS& oBuffData)
{
    auto pBuff = GetBuff(oBuffData.id());
    if (!pBuff)
    {
        if (!m_stData.buff.full())
        {
            m_stData.buff[oBuffData.id()].FromPb(oBuffData);
        }
    }
    return 0;
}

int NFCityPlayerBuffExt::DelBuff(const proto_ff::CityBuffOneCS& oBuffData)
{
    m_stData.buff.erase(oBuffData.id());
    return 0;
}

CityBuffOneCS* NFCityPlayerBuffExt::GetBuff(int id)
{
    auto iter = m_stData.buff.find(id);
    if (iter != m_stData.buff.end())
    {
        return &(iter->second);
    }
    return nullptr;
}
